package view.colorant;

import java.awt.Color;
import java.awt.Graphics;

import carte.Cellule;

public class AltitudeColorant extends Colorant {

	public Color[] crayons;
	private int max_height;
	
	public AltitudeColorant(int max_height){
		this(max_height, 0,0,0,255,255,255);
	}
	
	public AltitudeColorant(int max_height, Color low, Color high) {
		this(max_height, low.getRed(), low.getGreen(), low.getBlue(), high
				.getRed(), high.getGreen(), high.getBlue());

	}

	public AltitudeColorant(int max_height, int rl, int gl, int bl, int rh,
			int gh, int bh) {
		crayons = new Color[max_height];
		this.max_height = max_height;
		//step
		double rs = (rh - rl)/max_height;
		double gs = (gh - gl)/max_height;
		double bs = (bh - bl)/max_height;
		
		for (int i = 0; i < max_height; i++) {
			crayons[i] = new Color(rl, gl, bl);
			rl += rs;
			gl += gs;
			bl += bs;
		}
	}

	@Override
	public int getRed(Cellule c) {
		return crayons[getElevation(c)].getRed();
	}

	@Override
	public int getBlue(Cellule c) {
		return crayons[getElevation(c)].getBlue();
	}

	@Override
	public int getGreen(Cellule c) {
		return crayons[getElevation(c)].getGreen();
	}
	
	private int getElevation(Cellule c){
		//a la place d'afficher l'altitude, on affiche l'altitude + la hauteur des fluides
		int height = c.computeElevation();
		//par contre si ça depasse la hauteur maximale, on affiche la hauteur maximale (dans le cas des volcans)
		if(height >= max_height){
			height = max_height - 1;
		}
		return height;
	}

}
